﻿using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using Guan.CMS.Model.Extension;

namespace Guan.CMS.Web.ViewModels.Article
{
    public class ArticleFormModel
    {
        /// <summary>
        /// 编码
        /// </summary>
        [DisplayName("编码")]
        public int Id { get; set; }

        /// <summary>
        /// 已发布
        /// </summary>
        [DisplayName("已发布")]
        public bool IsPublished { get; set; }

        /// <summary>
        /// 已删除
        /// </summary>
        [DisplayName("已删除")]
        public bool IsDeleted { get; set; }

        /// <summary>
        /// 标题
        /// </summary>
        [DisplayName("标题")]
        public string Title { get; set; }

        /// <summary>
        /// 正文内容
        /// </summary>
        [DisplayName("正文")]
        public string Body { get; set; }

        /// <summary>
        /// 标签
        /// </summary>
        [DisplayName("标签")]
        public string Tags { get; set; }

        /// <summary>
        /// 作者
        /// </summary>
        [DisplayName("作者")]
        public string Author { get; set; }

        /// <summary>
        /// 阅读数
        /// </summary>
        [Display(Name = "阅读数")]
        public int Hits { get; set; }

        /// <summary>
        /// 开始时间
        /// </summary>
        [DisplayName("开始时间"), DisplayFormat(DataFormatString = "{0:yyyy-MM-dd HH:mm:ss}")]
        public DateTime? StartTime { get; set; }

        /// <summary>
        /// 结束时间
        /// </summary>
        [DisplayName("结束时间"), DisplayFormat(DataFormatString = "{0:yyyy-MM-dd HH:mm:ss}")]
        public DateTime? EndTime { get; set; }

        /// <summary>
        /// 添加时间
        /// </summary>
        [DisplayName("添加时间"), DisplayFormat(DataFormatString = "{0:yyyy-MM-dd HH:mm:ss}")]
        public DateTime CreatedTime { get; set; }

        /// <summary>
        /// 更新时间
        /// </summary>
        [DisplayName("更新时间"), DisplayFormat(DataFormatString = "{0:yyyy-MM-dd HH:mm:ss}")]
        public DateTime UpdatedTime { get; set; }

        #region 扩展属性

        /// <summary>
        /// 已过期
        /// </summary>
        [DisplayName("已过期")]
        public bool IsExpire { get { return this.EndTime.HasValue && this.EndTime.Value < DateTime.Now; } }

        /// <summary>
        /// 正文内容（纯文本）
        /// </summary>
        public string BodyText { get { return this.Body.HtmlToText(); } }

        /// <summary>
        /// 正文第一张图片
        /// </summary>
        public string FirstImage { get { return this.Body.GetFirstImages(); } }

        #endregion

        #region Category
        [DisplayName("分类")]
        public int CategoryId { get; set; }
        [DisplayName("分类")]
        public string CategoryName { get; set; }
        public string CategoryKey { get; set; }
        public bool CategoryIsPublished { get; set; }
        public bool CategoryIsDeleted { get; set; }
        #endregion

        [DisplayName("关键字")]
        public string MetaKeywords { get; set; }
        [DisplayName("描述")]
        public string MetaDescription { get; set; }
        [DisplayName("标题")]
        public string MetaTitle { get; set; }
        [DisplayName("友好名称")]
        public string FriendlyName { get; set; }

        #region SNS
        public int SNSId { get; set; }
        public string SNSDescription { get; set; }
        public string SNSText { get; set; }
        public string SNSPopTitle { get; set; }
        public string SNSTopHeight { get; set; }
        public string SNSComment { get; set; }
        public string SNSPictureUrl { get; set; }
        public bool SNSCatchedPic { get; set; }
        public string SNSWeiboUid { get; set; }
        #endregion
    }
}